package com.shj.em.biz.sell.service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.shj.em.biz.sell.entity.Target;
import com.shj.em.biz.sell.mapper.TargetMapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import com.baomidou.mybatisplus.plugins.Page;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;


/**
 * 年度销售目标 服务实现类
 *
 * @author Shen Huang Jian
 * @since 2018-07-15
 */
@Service
@Transactional
public class TargetServiceImpl extends ServiceImpl<TargetMapper, Target> implements TargetService {

    @Autowired
    TargetMapper targetMapper;

    public Page<Target> queryTargetPage(Map<String, Object> params){
        int offset = (Integer)params.get("offset");
        int pageSize = (Integer)params.get("limit");
        int pageNo = offset / pageSize + 1;
        Page<Target> page = new Page(pageNo, pageSize);
        List<Target> list = targetMapper.queryTargetPage(page, params);
        return page.setRecords(list);
    }

    public Target getTargetByYear(int year){
        Wrapper<Target> wrapper = new EntityWrapper();
        wrapper.eq("year", year);
        List<Target> list = targetMapper.selectList(wrapper);
        if(list == null || list.isEmpty()){
            return null;
        }else{
            return list.get(0);
        }
    }
}
